#include "const/oPreDefine.h"
#include "model/oActionInstant.h"

oCallFunc * oCallFunc::actionWithTarget(CCObject* pSelectorTarget,
	SEL_CallFunc selector) {
		oCallFunc *pRet = new oCallFunc();

		if (pRet && pRet->initWithTarget(pSelectorTarget)) {
			pRet->m_pCallFunc = selector;
			pRet->autorelease();
			return pRet;
		}

		CC_SAFE_DELETE(pRet);
		return nullptr;
}

bool oCallFunc::initWithTarget(CCObject* pSelectorTarget)
{
	m_pSelectorTarget = pSelectorTarget;
	return true;
}

CCObject * oCallFunc::copyWithZone(CCZone *pZone)
{
	return nullptr;
}

void oCallFunc::startWithTarget(CCNode *pTarget) {
	CCActionInstant::startWithTarget(pTarget);
	this->execute();
}

void oCallFunc::execute() {
	if (m_pCallFunc) {
		(m_pSelectorTarget->*m_pCallFunc)();
	}
}

//
// CallFuncN
//
void oCallFuncN::execute() {
	if (m_pCallFuncN) {
		(m_pSelectorTarget->*m_pCallFuncN)(m_pTarget);
	}
}

oCallFuncN * oCallFuncN::actionWithTarget(CCObject* pSelectorTarget,
	SEL_CallFuncN selector) {
		oCallFuncN *pRet = new oCallFuncN();

		if (pRet && pRet->initWithTarget(pSelectorTarget, selector)) {
			pRet->autorelease();
			return pRet;
		}

		CC_SAFE_DELETE(pRet);
		return nullptr;
}

bool oCallFuncN::initWithTarget(CCObject* pSelectorTarget,
	SEL_CallFuncN selector) {
		if (oCallFunc::initWithTarget(pSelectorTarget)) {
			m_pCallFuncN = selector;
			return true;
		}

		return false;
}

CCObject * oCallFuncN::copyWithZone(CCZone* zone)
{
	return nullptr;
}